<template>
  <div class="app-container beautify">
    <!--查询条件-->
    <div class="search-box" @keyup.enter="getList">
      <el-form :inline="true" :model="queryParams" class="demo-form-inline" ref="queryForm">
        <el-form-item label="计划名称:" size="small" prop="planName">
          <el-input v-model="queryParams.planName" clearable placeholder="请输入 计划名称" style="width: 160px"></el-input>
        </el-form-item>
        <el-form-item label="项目名称:" size="small" prop="projectName">
          <el-input v-model="queryParams.projectName" clearable placeholder="请输入 项目名称" style="width: 160px"></el-input>
        </el-form-item>
        <el-form-item label="审批状态:" size="small" prop="status">
          <el-select v-model="queryParams.status" size="small" clearable style="width: 160px">
            <el-option label="暂存" value="save"></el-option>
            <el-option label="审批中" value="active"></el-option>
            <el-option label="审批完成" value="completed"></el-option>
            <el-option label="作废、取消、删除" value="cancel"></el-option>
            <el-option label="退回、驳回" value="reject"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="small">
          <el-button type="primary" size="small" @click="handleQuery">查询</el-button>
          <el-button type="primary" size="small" @click="resetQuery" plain>清空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--查询条件-->

    <!--操作-->
    <div class="operate-box" style="margin: 15px 0;" ref="add">
      <el-button type="primary" size="small" plain icon="el-icon-plus"  @click="handleAdd" v-hasPermi="['designManager:procurementPlan:add']">新增</el-button>
    </div>
    <!--操作-->

    <el-table ref="elTable" :data="list" border size="mini" v-loading="loading" stripe :height="listHeight || fillHeight('listHeight',['queryForm','add','pagination'],['hamburger-container','tags-view-container'], 160)" @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="50" align="center" fixed></el-table-column>
      <el-table-column prop="planName" label="计划名称" min-width="200" align="center" fixed show-overflow-tooltip></el-table-column>
      <el-table-column prop="projectName" label="项目名称" min-width="200" align="center" fixed show-overflow-tooltip></el-table-column>
      <el-table-column prop="companyName" label="所在公司" min-width="200" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="planStartTime" label="计划开始日期" min-width="200" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="planEndTime" label="计划结束日期" min-width="200" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="createByName" label="申请人" min-width="200" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="createTime" label="申请时间" min-width="160" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="status" label="审批状态" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          {{getStatusName(scope.row.status)}}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button @click.native.prevent="handleEdit(scope.row.id, 'view')" type="text" size="small">查看</el-button>
          <el-button @click.native.prevent="handleEdit(scope.row.id, 'edit')" v-if="(scope.row.status == '' || scope.row.status == 'save' || scope.row.status == null ) || (scope.row.status == 'reject')" type="text" size="small" v-hasPermi="['designManager:procurementPlan:edit']">编辑</el-button>
          <el-button @click.native.prevent="checkApprove(scope.row)" type="text" v-if="!(scope.row.status == '' || scope.row.status == 'save' || scope.row.status == null )" size="small">审批详情</el-button>
          <el-button type="text" size="small" style="color: red" @click="handleDelete(scope.row)" v-if="(scope.row.status == '' || scope.row.status == 'save' || scope.row.status == null ) || (scope.row.status == 'reject')" v-hasPermi="['designManager:procurementPlan:delete']">删除</el-button>
          <el-button type="text" size="small" icon="el-icon-refresh" @click="srmSysnc(scope.row.id)" v-hasPermi="['designManager:procurementPlan:edit']" v-if="scope.row.status == 'completed'">同步</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--表格-->
    <!--    分页-->
    <BasePagination :that="this" ref="pagination"/>

  </div>
</template>

<script>
  import {delForm, listForm, srmSysnc} from "@/api/designManager/procurementPlan";
  import BaseIndex from "@/views/base/BaseIndex";
  import BasePagination from "@/views/base/BasePagination";
  import {newWindowBpm} from "@/utils/openBpm";

  export default {
    name: "DesignManagerProcurementPlan",
    components: {BasePagination},
    extends: BaseIndex,
    data() {
      return {
        queryParams: {
          planName: '',
          研发项目: '',
          status:'',
          pageNum:1,
          pageSize:20
        },//查询条件
        listHeight:0,//表格高度
        list: [],//表格数据
        form:{},
      }
    },

    created(){
      this.getList();
    },

    methods:{
      delForm,
      listForm,
      // 同步 数据
      srmSysnc(id){
        this.$confirm('确定是否同步?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          this.loading = true
          srmSysnc(id).then(
            res => {
              if (res.code==0){
                this.getList()
                this.$message.success('同步成功')
              }else{
                this.$message.warning('同步失败')
              }
              this.loading = false;
            }
          ).catch((err) => {
            this.loading = false;
            this.$message.warning('同步失败')
          })
        }).catch(() => {
        });
      },
      /**
       * 审批查询
       */
      checkApprove(data){
        newWindowBpm(data.instId,true,null,true, null);
      },

      handleAdd(){
        this.$router.push({
          path:'/designManager/procurementPlan/detail',
          query:{
            type:'add',
          }
        })
      },

      /**
       *编辑&&查看
       * @param id
       * @param type
       */
      handleEdit(id,type){
        this.$router.push({
          path:'/designManager/procurementPlan/detail',
          query:{
            type,id
          }
        })
      },
    }
  }
</script>
